import { IncomingHttpHeaders } from 'http';
import operate from '@dfeidao/atom-nodejs/db/operate';
import { productid, systemid } from '../../atom/config';

interface Message {
	filter: {
		company_no: string,
		high_company_name: string,
		company_name: string,
		corporate: string,
		contacts_tel_one: string,
		company_unity_code: string,
		org_code: string,
		nrollment_registration: string,
		contact: string,
		contacts_tel_two: string,
		business_address: string
	}
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}

interface IWebResult {
	// data: unknown;
	// cookie?: {
	// 	[name: string]: string;
	// } | null;
	// content_type?: string;
	// headers?: {
	// 	[key: string]: string[];
	// };
	// attachment?: string;
	// redirect?: string;
	// status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	const { exec, update } = operate(action_id, session_id, systemid);
	// 修改数据
	update('enterprise', { productid, company_no: message.filter.company_no }, { high_company_name: message.filter.high_company_name, company_name: message.filter.company_name, corporate: message.filter.corporate, contacts_tel_one: message.filter.contacts_tel_one, company_unity_code: message.filter.company_unity_code, org_code: message.filter.org_code, contact: message.filter.contact, contacts_tel_two: message.filter.contacts_tel_two, business_address: message.filter.business_address, nrollment_registration: message.filter.nrollment_registration, productid });

	const ret = await exec();
	return {
		data: ret
	}
}
